/*
 * @Author: your name
 * @Date: 2020-05-19 17:29:58
 * @LastEditTime: 2020-08-03 14:19:24
 * @LastEditors: zhengzhuang
 * @Description: In User Settings Edit
 * @FilePath: /C20Driver_1.0.0/lib/pages/carpool_page/index_carpool/windmill_order_progress.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/event/event_bus.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:C20Driver/service/request.dart';

/// 查询当前进行中的顺风车
class WindmillOrderProgress extends StatefulWidget {
  @override
  _WindmillOrderProgressState createState() => _WindmillOrderProgressState();
}

class _WindmillOrderProgressState extends State<WindmillOrderProgress> {
  Map _homeItineraryList = {}; // 顺风车列表

  @override
  void initState() {
    super.initState();
    // WidgetsBinding.instance.addPostFrameCallback((_){
    //   print('查询当前进行中的顺风车===========');
    //   _getFreeRideOrderList();
    // });
    _getFreeRideOrderList();
    eventBus.on<OrderWindmillTravel>().listen((event) {
      _getFreeRideOrderList();
    });
  }

  Future _getFreeRideOrderList() async {
    await Request.getFreeRideOrderList().then((value) {
      setState(() {
        _homeItineraryList = value;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    if (_homeItineraryList.length != 0) {
      return Positioned(
          top: ScreenUtil().setWidth(30.0),
          left: ScreenUtil().setWidth(30.0),
          child: InkWell(
            child: Container(
              width: ScreenUtil().setWidth(690.0),
              height: ScreenUtil().setWidth(100.0),
              decoration: BoxDecoration(
                  color: Colors.blueGrey,
                  borderRadius:
                      BorderRadius.circular(ScreenUtil().setSp(20.0))),
              padding: EdgeInsets.only(
                left: ScreenUtil().setWidth(30.0),
                right: ScreenUtil().setWidth(30.0),
              ),
              child: Row(
                children: <Widget>[
                  Icon(Icons.volume_up, color: Colors.white),
                  SizedBox(width: ScreenUtil().setWidth(20.0)),
                  Text('当前有一笔进行中的顺风车订单',
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(30.0),
                          color: Colors.white))
                ],
              ),
            ),
            onTap: () => NavigatorUtil.jump(
                    context, '/carpoolTrip?id=${_homeItineraryList['id']}')
                .then((res) {
              _getFreeRideOrderList();
            }),
          ));
    } else {
      return Container();
    }
  }
}
